<%@ page language="java" isELIgnored="false" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>引擎统计——恒拓运价魔方</title>
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/show.js"></script>
<link href="<%=request.getContextPath()%>/fare/css/base.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/fare/js/jquery-1.6.4.min.js"></script>
<link href="<%=request.getContextPath() %>/fare/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="<%=request.getContextPath() %>/fare/css/base.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/datePicker/WdatePicker.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/lib/ligerUI/js/ligerui.min.js"></script>
<script src="<%=request.getContextPath() %>/fare/lib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
<!-- 圆角文本框 -->
<link href="<%=request.getContextPath() %>/fare/css/htc/htc.css" rel="stylesheet" type="text/css" />
<script>
	function showm(sid) {
		var which = document.getElementById("lite" + sid);
		var imgmenu = document.getElementById("ling" + sid);
		if (which.style.display == "none") {
			document.getElementById("lite" + sid).style.display = "";
		} else {
			document.getElementById("lite" + sid).style.display = "none";
		}

	}
</script>
<style type="text/css">
<!--
.STYLE1 {
	color: #3366cc
}
-->
</style>

<script type="text/javascript">
var manager;

var recolumns = [
{ display: '序号', name: 'rowId', width: 40, render: function(data, index) { return (this.options.page-1)*this.options.pageSize+index+1;} },
{ name: 'grabdate', display: '抓取日期', align:'center',width:100},
{ name: 'grabchannel', display: '抓取渠道', align:'center',width:100},
{ name:'allbyteLength',display: '流量大小(m)', align:'center',width:80},
{ name:'total',display: '总次数', align:'center',width:60,
	render: function (record, rowindex, value, column){
			return "<a href=\"javaScript:open_detail_2();\">"+record.total+"</a>";
		}
	
	},
{ name: 'successNum', display: '成功次数', align:'center',width:60,
	 render: function (record, rowindex, value, column){
		  var status='3';
	 	  return "<a href=\"javaScript:open_detail("+status+");\">"+record.successNum+"</a>";
	 }
},
{ display:'抓取成功率',width: 70,align:'center',
	render:function (row){
		if(row.total==0 || row.successNum==0)
			return "<b style=\'color:red\'>"+"0%"+"</b>";
		var percentSuccess = Math.round(row.successNum/(row.total-row.waiting-row.starting) * 1000)/10;
		if(percentSuccess<=80)
			return "<b style=\'color:red\'>"+percentSuccess+"%</b>";
		else if(percentSuccess<=90 && percentSuccess > 80)
			return "<b style=\'color:blue\'>"+percentSuccess+"%</b>";
		else
			return "<b style=\'color:green\'>"+percentSuccess+"%</b>";
	}
},
{ display: '任务', columns:
	[
	{ display: '抓取失败', name: 'secondFail',width:60, align:'center',
		//查看详细失败信息
		 render: function (record, rowindex, value, column){
			var status='-2';
		 	return "<a href=\"javaScript:open_detail("+status+");\">"+record.secondFail+"</a>";
		 }
   },
   { display: '解析失败', name: 'thirdFail',width:60, align:'center',
	 	 render: function (record, rowindex, value, column) {
	 		var status='-3';
	 		return "<a href=\"javaScript:open_detail("+status+");\">"+record.thirdFail+"</a>";
	 	 }
	 	 },
   { display: '其他失败', name: 'forthFail',width:60, align:'center',
		render: function (record, rowindex, value, column){ 
			var status='-4';
			return "<a href=\"javaScript:open_detail("+status+");\">"+record.forthFail+"</a>";
		}
	},
	{ display: '等待中', name: 'waiting',width:60, align:'center',
	 	 render: function (record, rowindex, value, column) {
	 		var status='0';
	 		return "<a href=\"javaScript:open_detail("+status+");\">"+record.waiting+"</a>";
	 	 }
	},
	//{ display: '启动中', name: 'starting',width:60, align:'center',
	 //	 render: function (record, rowindex, value, column) {
	 //		var status='1';
	 //		return "<a href=\"javaScript:open_detail("+status+");\">"+record.starting+"</a>";
	 //	 }
	//},
	{ display: '执行中', name: 'working',width:60, align:'center',
	 	 render: function (record, rowindex, value, column) {
	 		var status='1';
	 		return "<a href=\"javaScript:open_detail("+status+");\">"+record.starting+"</a>";
	 	 }
	}
	]
},
{ name: 'actualNum', display: '实际抓取数量',width: 80,align:'center'},
{ display:'ID',name:'grabchannelID',width:50,hide:true}
];

$(function (){
	var ps = $("#ps").val();
	if(ps!="" && ps=="re"){
		 	var menu;
	        var grabchannelID;
	        var bstime;
	        function itemclickF(item, i)
	        {
	        	$("#grabchannelId").val(grabchannelID+"");
	        	$("#bstime").val(bstime+"");
	        	$("#status").val("fail");
				$("#fsform").submit(); 
	        }
	        function itemclickS(item, i)
	        {
	        	$("#grabchannelId").val(grabchannelID+"");
	        	$("#bstime").val(bstime+"");
	        	$("#status").val("succse");
	        	$("#fsform").submit();
	        }
		
		var gname = $("#gname").val();
		if(gname!=""){
			$("#Reportgrabchannel").val(gname);
		}
		var btime = $("#btime").val();
		var etime = $("#etime").val();
		if(btime!="" && etime!=""){
			$("#beginTime").val(btime);
			$("#endTime").val(etime);
		}
		var rtype = $("#rtype").val();
		if(rtype!="All"){
			$("#ReportType").val(rtype);
		}
		if(rtype==""){
			$("#ReportType").val("All");
		}
		
		var sytype = $("#sytype").val();
		if(sytype!=""){
			$("#SymbolType").val(sytype);
		}
	    var tnum = $("#tnum").val();
	    $("#tjnum").val(tnum);
		var griddata=${data};
		
		manager = $("#re").ligerGrid({
		         columns:recolumns, data: { Rows: griddata },title:'引擎统计',showTitle:true,pageSize: 10,
		         usePager: false,
	             onAfterShowData: function(){mergecell("#re", "c102");
	                        $("tr",$(manager)).each(function ()
	                        {
	                            $(this).mouseover(function() {$(this).css("cursor","pointer"); $(this).ligerTip({ content: "右键查看本条详细" });}); 
	                            $(this).mouseout(function() {$(this).ligerHideTip({ content: $(this).text() });} );                                                                 
	                        });
	             },allowUnSelectRow:true,
	             onRClickToSelect:true,onContextmenu : function (parm,e)
	                {
	            	 	bstime = parm.data.grabdate;
	            	 	grabchannelID = parm.data.grabchannel;
	                    //menu.show({ top: e.pageY, left: e.pageX});
	                    return false;
	                }
		});
		$("#re").css("display","block");
		$("#reseachBy").css("display","block");
	}
	
});

//弹出点击总数的信息
function open_detail_2()
{
	var manager = $("#re").ligerGetGridManager();
	var row = manager.getSelectedRow();
	var url='<%=request.getContextPath() %>/fare/view_tatol_detail.jsp?grabchannelID='+row.grabchannelID+'&grabchannel='+row.grabchannel+'&grabdate='+row.grabdate+'&rd='+Math.random();;
	//在当前窗口重新打开一个
	parent.f_addTab("total_1","引擎统计_总次数", url);
}

//弹出失败状态的详细信息	
function open_detail(status)
{
	var manager = $("#re").ligerGetGridManager();
	var row = manager.getSelectedRow();

	var url='<%=request.getContextPath() %>/fare/view_fail_detail.jsp?grabchannelID='+row.grabchannelID+'&grabchannel='+row.grabchannel+'&grabdate='+row.grabdate+'&status='+status+'&rd='+Math.random();;
	//window.open (url,'newwindow','height=1000,width=4000,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no',false);
	//location.href=url;
	var showTest;
	var testG;
	if(status==3){
		showTest="成功次数";
		testG="success_total";
	}
	if(status==-2){
		showTest="抓取失败";
		testG="fail_get";
	}
	if(status==-3){
		showTest="解析失败";
		testG="fail_re";
	}
	if(status==-4){
		showTest="其他失败";
		testG="fail_other";
	}
	if(status==0){
		showTest="等等中";
		testG="fail_wait";
	}
	if(status==1){
		showTest="执行中";
		testG="fail_ing";
	}
	parent.f_addTab(""+testG+"","引擎统计_"+showTest+"", url);
}

	//查询
	function onSubmit() {
			$("#sourceForm").submit();
	}
	
	function mergecell(gridid, columnid) //参数:表格id和列索引关键字，根据表格具体值来动态合并单元格
    {
        var i, j, k, x;
        i = -1; k = 1; j = ""; x = 0;
        var cellname = "";

        $("td[id$='|" + columnid + "']", gridid).each(
               function() {
                   if (j == $("div", this).text()) {
                       $(this).addClass("l-remove");
                       k++;
                       $("td[id='" + cellname + "']", gridid).attr("rowspan", k.toString());
                   }
                   else {
                       j = $("div", this).text();
                       var a = $(this);
                       cellname = a.attr("id"); //得到点击处的id                            
                       k = 1;
                       x = i;
                   }
                   i++;
               });
        $(".l-remove").remove();
    }
    //-------------------------------------------------------------------------------------------------------------------------------
    function mergecell2(gridid, columnid,groupcolumnid) //参数:表格id和列索引关键字，根据表格具体值来动态合并单元格，按某列分组
    {
    	//alert(groupcolumnid);
        var i, j, k, x;
        i = -1; k = 1; j = ""; x = 0;
        var cellname = "";
		
        $("td[id$='|" + columnid + "']", gridid).each(
               function() {
                   var b = $(this);
                   var cx = b.attr("id");
                   cx = cx.replace(columnid, groupcolumnid);
                   var groupvalue=$("td[id='" + cx + "']", gridid).text(); //得到这个单元格所在行的分组那一个格的值
                   if (j == $("div", this).text() + groupvalue) {
                       $(this).addClass("l-remove");
                       k++;
                       $("td[id='" + cellname + "']", gridid).attr("rowspan", k.toString());
                   }
                   else {
                       j = $("div", this).text() + groupvalue;
                       var a = $(this);
                       cellname = a.attr("id"); //得到点击处的id                            
                       k = 1;
                       x = i;
                   }
                   i++;
               });
        $(".l-remove").remove();
    }
	
	//根据条件查询抓取统计报表
	function seachreBy(){
		var Reportgrabchannel = $("#Reportgrabchannel").val();
		var sdate = $("#beginTime").val();
		var edate = $("#endTime").val();
		
        var s_date = new Date(sdate.replace(/-/g,"/"));
        var e_date = new Date(edate.replace(/-/g,"/"));
        var y_gap=e_date.getFullYear()-s_date.getFullYear();
        var m_gap = y_gap*12 + e_date.getMonth()-s_date.getMonth();
        var d_gap = e_date.getDate()-s_date.getDate();
        
        var time1 = s_date.getTime();
    	var time2 = e_date.getTime();
    	if(time1>time2){
    		alert("结束时间不能小于开始时间");
    		return;
    	}
    	$("#sourceForm").attr("action","fswInfoAction!getStatisticsTaskReport.action");
		
    	$("#sourceForm").submit();
	}
	
</script>
</head>

<body>
	<form action="fswInfoAction!getFwsInfoByPage.action" method="post" id="sourceForm" name="sourceForm">
	<input name="gname" id="gname" type="hidden" value="${Reportgrabchannel}"/>
	<input name="btime" id="btime" type="hidden" value="${beginTime}"/>
	<input name="etime" id="etime" type="hidden" value="${endTime}"/>
	<input name="rtype" id="rtype" type="hidden" value="${ReportType}"/>
	<input name="sytype" id="sytype" type="hidden" value="${SymbolType}"/>
	<input name="tnum" id="tnum" type="hidden" value="${tjnum}"/>
	<input type="hidden" id="ps" name="ps" value="${ps}"/>
	
	<%-- <div>
		<div id="reseachBy" style="display: none;padding-top: 0px;padding-bottom: 2px;">
		<table width="100%" cellpadding="0" cellspacing="5">
			<tr>
				<td align="left">
					渠道&nbsp;&nbsp;
			<select class="easyui-combobox" name="Reportgrabchannel" style="width: 150px;" id="Reportgrabchannel">
				<option value="" selected="selected">————请选择————</option>
				<c:choose>
					<c:when test="${channelSourceList == null}">
					</c:when>
					<c:otherwise>
						<c:forEach var="item" items="${channelSourceList }">
							<option value="${item.name}">${item.name}</option>
						</c:forEach>
					</c:otherwise>
				</c:choose>
		    </select>
				</td>
				<td align="left">
					日期范围:
				</td>
				<td align="left">
					<input id="beginTime" style="width: 100px;" value="" onclick="WdatePicker();" name="beginTime" type="text" readOnly="true"/>
						--
					<input id="endTime" onclick="WdatePicker();" style="width: 100px;" value="" name="endTime" type="text" readOnly="true"/>
				</td>
				<td align="left">
					<input type="button" value="查询" onclick="seachreBy();"/>
					<input type="reset" value="重置 "/>
					<input type="button" onclick="reload()" value="刷新"/> 
				</td>
				<td>
			</tr>
		</table>
		</div>
	</div>
		 --%>
	</form>
	
	<form action="fswInfoAction!getTaskRecord.action" method="post" id="fsform" name="fsform">
		<input name="bstime" id="bstime" type="hidden" value=""/>
		<input name="grabchannelId" id="grabchannelId" type="hidden" value=""/>
		<input name="status" id="status" type="hidden"/>
		<input name="tStatus" id="tStatus" type="hidden" value="${status}"/>
	</form>
	
	<!-- 存放查询数据的DIV -->
		<div id="re" align="center" style="width: 400;display:none;padding-top: 0px;">
		</div>
</body>
</html>
<script>
	function reload(){
		//window.location.href='fswInfoAction!getStatisticeByReport.action';
		window.location.reload();
	}
</script>
